package data_structure;

public class leetcode_1047 {
    public String removeDuplicates(String s) {
        int len=s.length();
        char[] stack=new char[len];
        int current=0;
        for(int i=0;i<len;++i){
            if(current>0){
                if(s.charAt(i)==stack[current-1]){
                    current--;
                }
                else{
                    stack[current]=s.charAt(i);
                    current++;
                }
            }
            else{
                stack[current]=s.charAt(i);
                current++;
            }
        }
        String result="";
        for(int i=0;i<current;++i){
            result+=stack[i];
        }
        return result;
    }
}
